import {observable} from 'mobx'; 
import Taro from '@tarojs/taro';
import * as cfapi from '../api/cfApi';
import {http,getStorage} from '../util/common';

const loginstore = observable({
  name: 'login',
  token: getStorage('token'),
  tel: '',
  loginInfo: {},
  getCode(params) {
    console.log('getCode()',loginstore.token)
    // 获取验证码
    http({
      url: cfapi.GET_CODE,
      method: 'POST',
      data: params
    }).then(res => {
      console.log('http 请求回来的', res)
    })
  },
  login(params) {
    return http({
      url: cfapi.VERIFY_CODE,
      method: 'POST',
      data: params
    }).then(res => {
      console.log('http 请求回来的', res)
      if(res.code===200) {
        //请求成功
        return res
      } else if(res.code===400) {
        Taro.showToast('登录失败')
      }
    })
  }
})
export default loginstore